﻿using LoA.Shared.Input;
using Microsoft.Xna.Framework;

namespace LoA.InputEngine {
	public partial class InputComponent {
		/// <summary>
		/// Allows the game component to update itself.
		/// </summary>
		/// <param name="gameTime">Provides a snapshot of timing values.</param>
		public override void Update(GameTime gameTime) {
			for (int i = 0; i < inputManagers.Length; ++i) {
				// Expire old moves.
				if (gameTime.TotalGameTime - playerMoveTimes[i] > MoveTimeOut) {
					playerMoves[i] = null;
				}

				// Get the updated input manager.
				InputManager inputManager = inputManagers[i];
				inputManager.Update(gameTime);

				// Detection and record the current player's most recent move.
				MoveSequence newMove = moveList.DetectMove(inputManager);
				if (newMove != null) {
					playerMoves[i] = newMove;
					playerMoveTimes[i] = gameTime.TotalGameTime;
				}
			}

			base.Update(gameTime);
		}
	}
}
